<?php

class AuthRuleModel extends Model
{

    public function getAll()
    {
        $data = $this->where('ismenu=1')->select();
        return $data;
    }


    /**
     * 获取当前菜单
     * @author Mr.Weng
     */
    public function getCurrentMenu()
    {
        $map['status'] = array('eq', 1);
        $map['name'] = GROUP_NAME . '/' . MODULE_NAME . '/' . ACTION_NAME;

        $result = $this->where($map)->order('pid desc')->find();
        return $result;
    }

    /**
     * 根据菜单ID的获取其所有父级菜单
     * @param array $current 当前菜单信息
     * @return array 父级菜单集合
     * @author Mr.Weng
     */
    public function getParentMenu($current)
    {
        $res[] = $current;
        if (empty($current)) {
            return $res;
        }
        $map['status'] = array('eq', 1);
        $map['id'] = $current['pid'];
        $menu = $this->where($map)->find();
        array_unshift($res, $menu);

        if ($menu['pid']) {
            $map['id'] = $menu['pid'];
            $menu = $this->where($map)->find();
            array_unshift($res, $menu);
        }
        
        return $res;
    }
}